<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>aop</title>
</head>
<body>
    <script>
        Function.prototype.before = function(beforeFn){
            //保留当前函数的引用
            let _self = this;
            return function(){
                let retVal = beforeFn.apply(this,arguments);
                retVal != false && (retVal = _self.apply(this,arguments));
                return retVal;
            }
        }

        Function.prototype.after = function(afterFn){
            //保留当前函数的引用
            let _self = this;
            return function(){
                let retVal = _self.apply(this,arguments)
                retVal != false && afterFn.apply(this,arguments)
                return retVal;
            }
        }

        let layer = function(){
            alert("弹窗！！");
            return false;
        }

        layer = layer.before(function(){
            alert("弹框弹出前！！")
            return true;
        })
        .after(function(){                                                                                                                                                                                                                                                                                                                                           
            alert("弹框弹出后！！")
        });

        // layer = layer.after(function(){
        //     alert("弹框弹出后！！")
        // });

        layer();
    </script>
</body>
</html>